package opertion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOpertion implements IOperation {
    @Override
    public void work(BookList bookList) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要增加的书名");
        String name=sc.nextLine();
        System.out.println("请输入你要增加书的作者");
        String author=sc.nextLine();
        System.out.println("请输入你要增加书的类型");
        String type=sc.nextLine();
        System.out.println("请输入你要增加书的价格");
        int price=sc.nextInt();
        Book book=new Book(name,author,type,price);
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if (bookList.getBooks()[i].equals(book)){
                System.out.println("有该书，无需添加");
                return;
            }
        }
        bookList.getBooks()[bookList.getUsedSize()]=book;
        bookList.setUsedSize(bookList.getUsedSize()+1);
        System.out.println("添加成功");
    }
}
